package com.naicheng.ivote.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.naicheng.ivote.R;
import com.naicheng.ivote.doman.HotCommentListBean;
import com.naicheng.ivote.doman.HotCommentsChildBean;
import com.naicheng.ivote.doman.HotOptionsBean;
import com.naicheng.ivote.uiself.CommentChildLinearForListView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CommentListAdapter extends BaseAdapter {

    private Context context;
	private LayoutInflater mInflater;
    private ArrayList<HotCommentListBean> list;

    /**
     * 
     * @param context
     * @param list
     */
    public CommentListAdapter(Context context,ArrayList<HotCommentListBean> list)
    {
    	this.context=context;
    	this.list = list;
    	this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }


    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
    	ViewHolder	holder;
    	if(convertView == null){
    		holder = new ViewHolder();
    		convertView = mInflater.inflate(R.layout.hotdetail_comment_item, null);
    		holder.TextViewfloor = (TextView) convertView.findViewById(R.id.hotdetail_comment_floor);
    		holder.TextViewtext = (TextView) convertView.findViewById(R.id.hotdetail_comment_text);
    		holder.TextViewcreatetime = (TextView) convertView.findViewById(R.id.hotdetail_comment_createtime);
    		holder.TextViewsex = (TextView) convertView.findViewById(R.id.hotdetail_comment_sex);
    		holder.TextViewaccount = (TextView) convertView.findViewById(R.id.hotdetail_comment_account);
    		holder.hotdetail_comment_child_list = (CommentChildLinearForListView) convertView.findViewById(R.id.hotdetail_comment_child_list);
    		
    		convertView.setTag(holder);
    		convertView.setId(position);
    	}else{
    		holder = (ViewHolder) convertView.getTag();
    	}
    	holder.TextViewfloor.setText(list.get(position).getFloor()+"楼：");
    	holder.TextViewtext.setText(list.get(position).getText());
    	holder.TextViewcreatetime.setText(list.get(position).getCreatetime());
    	if("f".equals(list.get(position).getSex())){
			holder.TextViewsex.setText(R.string.list_item_sex2);
			holder.TextViewsex.setTextColor(context.getResources().getColor(R.color.sex_zi));
		}else{
			holder.TextViewsex.setText(R.string.list_item_sex1);
			holder.TextViewsex.setTextColor(context.getResources().getColor(R.color.sex_lan));
		}
    	holder.TextViewaccount.setText(list.get(position).getAccount());
    	
    	if(null!=list.get(position).getReplys()){
    		CommentChildListAdapter adapter=new  CommentChildListAdapter(context, list.get(position).getReplys());
    		holder.hotdetail_comment_child_list.setAdapter(adapter);
    	}else{
    		HotCommentsChildBean bean=new HotCommentsChildBean();
    		bean.setReplyid(1);
    		bean.setType(1);
    		bean.setText("莫说沉迷似乎非宋康明反馈思密达可免费肯定嘛反馈单困死了目瞪口呆耍流氓灵敏度");
    		HotCommentsChildBean bean2=new HotCommentsChildBean();
    		bean2.setReplyid(2);
    		bean2.setType(2);
    		bean2.setText("莫说沉迷似乎非宋康明反馈思密达可免费肯定嘛反馈单困死了目瞪口呆耍流氓灵敏度");
    		ArrayList<HotCommentsChildBean> Replys=new ArrayList<HotCommentsChildBean>();
    		Replys.add(bean);
    		Replys.add(bean2);
    		CommentChildListAdapter adapter=new CommentChildListAdapter(context, Replys);
    		holder.hotdetail_comment_child_list.setAdapter(adapter);
    	}
    	
    	
    	holder.TextViewtext.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				System.out.println("ffffffff");
			}
		});
        return convertView;
    }

    public class ViewHolder
    {
    	public TextView TextViewfloor;
    	public TextView TextViewtext;
    	public TextView TextViewcreatetime;
    	public TextView TextViewsex;
    	public TextView TextViewaccount;
    	public CommentChildLinearForListView hotdetail_comment_child_list;
    	
    }
    
}
